/*
//  Copyright © 2014 Allen County Public Library.

  //        ACPL Mobile is free software: This program is distributed and you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  ACPL Mobile is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, including without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ACPL Mobile. If not, see http://www.gnu.org/licenses/.
 * Author: James Harpe
 * 
 * Description: This class contains the fragment responsible for displaying a user's fines. 
 */

package us.in.lib.acpl.Mobile_ACPL;

import java.util.List;

import com.google.analytics.tracking.android.EasyTracker;


import us.in.lib.acpl.Mobile_ACPL.adapters.FineListAdapter;
import us.in.lib.acpl.Mobile_ACPL.context.Mobile_ACPL;
import us.in.lib.acpl.Mobile_ACPL.patron.Fine;
import us.in.lib.acpl.Mobile_ACPL.ws.AccountInfoHandler;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class AccountFinesFragment extends ListFragment {
	private boolean noFines = false;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		RelativeLayout fragView = (RelativeLayout) inflater.inflate(
				R.layout.account_fines, container, false);
		fragView.findViewById(R.id.payFinesButton).setOnClickListener(
				new ButtonListener());
		TextView t = (TextView) fragView.findViewById(R.id.totalFines);
		AccountActivity act = (AccountActivity) getActivity();
		t.setText("Total Owed: $" + act.getAccHandler().getTotalFines());
		if (noFines) {
			fragView.findViewById(R.id.noFines).setVisibility(View.VISIBLE);
		}
		return fragView;
	}

	public void OnCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	public void setList() {
		AccountActivity act = (AccountActivity) getActivity();
		AccountInfoHandler handler = act.getAccHandler();
		List<Fine> fines = handler.getFines();

		if (this.getListAdapter() == null) {

			this.setListAdapter(new FineListAdapter(this.getActivity(), fines));
		} else {
			FineListAdapter ad = (FineListAdapter) this.getListAdapter();

			ad.notifyDataSetChanged();

		}
		if (fines.size() == 0) {
			View v = getActivity().findViewById(R.id.noFines);

			this.noFines = true;
			if (v != null) {
				v.setVisibility(View.VISIBLE);
			}
		}
	}

	private class ButtonListener implements OnClickListener {

		@Override
		public void onClick(View arg0) {

            //ACPL: Removed ecommerce URL
			Uri uri = Uri
					.parse("");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);

			EasyTracker.getTracker().sendEvent("Fines", "Pay Fines Button Pressed", null, null);
		}

	}
	
}
